﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using TSVNAddin.SVN;
using Rhino.Mocks;

namespace TSVNAddin.Core.Test
{
	[TestFixture]
	public class WorkingRootFinderFixture
	{
		[Test]
		public void Found()
		{
            var svnClientAdapter = MockRepository.GenerateStub<SVNClientAdapter>();
            svnClientAdapter.Stub(x => x.IsWorkingCopy(@"c:\svnroot\myproject\trunk\newfolder\")).Return(false);
            svnClientAdapter.Stub(x => x.IsWorkingCopy(@"c:\svnroot\myproject\trunk\")).Return(true);
            svnClientAdapter.Stub(x => x.IsWorkingCopy(@"c:\svnroot\myproject\")).Return(false);
            svnClientAdapter.Stub(x => x.IsWorkingCopy(@"c:\svnroot\")).Return(true);

			var finder = new WorkingRootFinder(svnClientAdapter);
			string root = finder.FindRoot(@"c:\svnroot\myproject\trunk\newfolder\myproject.sln");

			Assert.AreEqual(@"c:\svnroot\", root);
		}

        [Test]
		public void Found2()
		{
            var svnClientAdapter = MockRepository.GenerateStub<SVNClientAdapter>();
            svnClientAdapter.Stub(x => x.IsWorkingCopy(@"c:\svnroot\myproject\trunk\newfolder\")).Return(false);
            svnClientAdapter.Stub(x => x.IsWorkingCopy(@"c:\svnroot\myproject\trunk\")).Return(true);
            svnClientAdapter.Stub(x => x.IsWorkingCopy(@"c:\svnroot\myproject\")).Return(false);
            svnClientAdapter.Stub(x => x.IsWorkingCopy(@"c:\svnroot\")).Return(false);

			var finder = new WorkingRootFinder(svnClientAdapter);
            string root = finder.FindRoot(@"c:\svnroot\myproject\trunk\newfolder\myproject.sln");

            Assert.AreEqual(@"c:\svnroot\myproject\trunk\", root);
		}

		[Test]
		public void DoesNotFound()
		{
            var svnClientAdapter = MockRepository.GenerateStub<SVNClientAdapter>();
            svnClientAdapter.Stub(x => x.IsWorkingCopy(@"c:\svnroot\myproject\trunk\newfolder\")).Return(false);
            svnClientAdapter.Stub(x => x.IsWorkingCopy(@"c:\svnroot\myproject\trunk\")).Return(false);
            svnClientAdapter.Stub(x => x.IsWorkingCopy(@"c:\svnroot\myproject\")).Return(false);
            svnClientAdapter.Stub(x => x.IsWorkingCopy(@"c:\svnroot\")).Return(false);
            svnClientAdapter.Stub(x => x.IsWorkingCopy(@"c:\")).Return(false);

			var finder = new WorkingRootFinder(svnClientAdapter);
            string root = finder.FindRoot(@"c:\svnroot\myproject\trunk\newfolder\myproject.sln");

			Assert.AreEqual(string.Empty, root);
		}
	}
}
